package emediashared.ui;

import java.io.File;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.jobs.ISchedulingRule;

import emediashared.model.IRemoteFile;

public class RemoteNode implements ISchedulingRule {
	private RemoteNode parent;
	private String name;
	private boolean isLoaded;
	private boolean isLoading;
	private String filePath;
	private boolean isDirectory;
	private boolean isDownloaded;
	private List<RemoteNode> children = new ArrayList<RemoteNode>();

	public RemoteNode(IRemoteFile remoteFile, RemoteNode parent) {
		try {
			this.parent = parent;
			filePath = remoteFile.getFilePath();
			isDirectory = remoteFile.isDirectory();
			this.name = new File(filePath).getName();
			if (!isDirectory) {
				isLoaded = true;
			}
		} catch (RemoteException e) {
			// ignore
		}
	}

	@Override
	public boolean contains(ISchedulingRule rule) {
		return rule == this;
	}

	@Override
	public boolean isConflicting(ISchedulingRule rule) {
		return rule == this;
	}

	public String getName() {
		return name;
	}

	public String getFilePath() {
		return filePath;
	}
	
	public boolean isDirectory() {
		return isDirectory;
	}
	
	public List<RemoteNode> getChildren() {
		return children;
	}

	public boolean isLoaded() {
		return isLoaded;
	}

	public boolean isLoading() {
		return isLoading;
	}

	public void setLoaded(boolean isLoaded) {
		this.isLoaded = isLoaded;
	}

	public void setLoading(boolean isLoading) {
		this.isLoading = isLoading;
	}
	
	public RemoteNode getParent() {
		return parent;
	}
	
	public void setDownloaded(boolean isDownloaded) {
		this.isDownloaded = isDownloaded;
	}
	
	public boolean isDownloaded() {
		return isDownloaded;
	}

}
